import axios from 'axios'
import showMessage from '../utils/showMessage'

const ins = axios.create() // 创建一个axios的实例
ins.interceptors.response.use(function (resp) {
  if (!resp.data.code && !resp.data.data) {
    //处理验证码接口响应
    return resp.data
  }
  if (resp.data.code !== 0 && resp.data.code !== 406) {
    showMessage({
      content: resp.data.msg || '接口请求失败',
      type: 'error',
      duration: 1500
    })
    return null
  }
  return resp.data.data
})

export default ins
